package com.ruoyi.develop.goodsReceipt.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.develop.goodsReceipt.domain.GoodsReceipt;
import com.ruoyi.develop.goodsReceipt.service.IGoodsReceiptService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 签收单Controller
 * @author qh
 * @date 2023-01-05
 */
@RestController
@RequestMapping("/goodsReceipt/goodsReceipt")
public class GoodsReceiptController extends BaseController {
    @Autowired
    private IGoodsReceiptService goodsReceiptService;

    /**
     * 查询签收单列表
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsReceipt:query')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsReceipt entity) {
        startPage();
        List<GoodsReceipt> list = goodsReceiptService.selectList(entity);
        return getDataTable(list);
    }

    /**
     * 导出签收单列表
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsReceipt:export')")
    @Log(title = "签收单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsReceipt entity) {
        List<GoodsReceipt> list = goodsReceiptService.selectList(entity);
        ExcelUtil<GoodsReceipt> util = new ExcelUtil<GoodsReceipt>(GoodsReceipt. class);
        util.exportExcel(response, list, "签收单数据");
    }

    /**
     * 获取签收单详细信息
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsReceipt:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(goodsReceiptService.selectById(id));
    }

    /**
     * 新增签收单
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsReceipt:add')")
    @Log(title = "签收单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody GoodsReceipt entity) {
        return toAjax(goodsReceiptService.insert(entity));
    }

    /**
     * 修改签收单
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsReceipt:edit')")
    @Log(title = "签收单", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody GoodsReceipt entity) {
        return toAjax(goodsReceiptService.update(entity));
    }

    /**
     * 删除签收单
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsReceipt:remove')")
    @Log(title = "签收单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(goodsReceiptService.deleteByIds(ids));
    }
}
